home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / sprites / untdemo2.pas < prev    next >
Pascal/Delphi Source File  |  1995-12-22  |  3KB  |  114 lines

  1. unit Untdemo2;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, Mchsprt, ExtCtrls, MChSpBg;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     MChSpriteBgr1: TMChSpriteBgr;
  12.     MChSprite1: TMChSprite;
  13.     MChSprite2: TMChSprite;
  14.     MChSprite3: TMChSprite;
  15.     procedure FormCreate(Sender: TObject);
  16.   private
  17.     { Private declarations }
  18.   public
  19.     { Public declarations }
  20.   end;
  21.  
  22. function Sprite2PosFunc(AtTime: TDateTime):TPoint;
  23. function Sprite3PosFunc(AtTime: TDateTime):TPoint;
  24. procedure OnCollide(SprCollided: TMChSprite; AtTime: TDateTime);
  25. procedure NoCollide(AtTime: TDateTime);
  26.  
  27. var
  28.   Form1: TForm1;
  29.  
  30. implementation
  31.  
  32. {$R *.DFM}
  33.  
  34. var
  35.   CollideFlip: Boolean;
  36.  
  37. function Sprite3PosFunc(AtTime: TDateTime):TPoint;
  38.   var
  39.     x,y,alpha: double;
  40.   begin
  41.   alpha:= 2*Pi*(AtTime-Form1.MChSprite3.SprTimeStarted)*24.0*60.0+(90.0+0.0)/180.0*Pi;
  42.   x := Form1.MChSpriteBgr1.ClientWidth /2.0 +
  43.       (Form1.MChSpriteBgr1.ClientWidth /3.0)*cos(alpha);
  44.   y := Form1.MChSpriteBgr1.ClientHeight /2.0 +
  45.     - (Form1.MChSpriteBgr1.ClientWidth /3.0)*sin(alpha);
  46.   Sprite3PosFunc:=Point(round(x),round(y));
  47.   Form1.MChSprite3.SprSetScale(1-1.0*sin(alpha));
  48.   end;
  49.  
  50. function Sprite2PosFunc(AtTime: TDateTime):TPoint;
  51.   var
  52.     x,y,alpha: double;
  53.   begin
  54.   alpha:=-2*Pi*(AtTime-Form1.MChSprite2.SprTimeStarted)*24.0*60.0+(90.0-180.0)/180.0*Pi;
  55.   x := Form1.MChSpriteBgr1.ClientWidth /2.0 +
  56.       (Form1.MChSpriteBgr1.ClientWidth /3.0)*cos(alpha);
  57.   y := Form1.MChSpriteBgr1.ClientHeight*0.5 +
  58.     - (Form1.MChSpriteBgr1.ClientWidth *0.55)*sin(alpha);
  59.   Sprite2PosFunc:=Point(round(x),round(y));
  60.   if x>Form1.MChSpriteBgr1.ClientWidth div 2
  61.     then Form1.MChSprite2.SprSetScaleX( (1-1.0*sin(alpha)))
  62.     else Form1.MChSprite2.SprSetScaleX(-(1-1.0*sin(alpha)));
  63.   if y<Form1.MChSpriteBgr1.ClientHeight div 2
  64.     then Form1.MChSprite2.SprSetScaleY( (1-1.0*sin(alpha)))
  65.     else Form1.MChSprite2.SprSetScaleY(-(1-1.0*sin(alpha)));
  66.   end;
  67.  
  68. procedure TForm1.FormCreate(Sender: TObject);
  69.   begin
  70.   MChSprite3.SprPosFunc:=Sprite3PosFunc;
  71.   MChSprite2.SprPosFunc:=Sprite2PosFunc;
  72.   MChSprite3.SprOnCollide:=OnCollide;
  73.   MChSprite3.SprNoCollide:=NoCollide;
  74.   MChSprite3.SprCruise(-1);
  75.   MChSprite2.SprCruise(-1);
  76.   MChSprite1.SprShowAt(Point(Form1.MChSpriteBgr1.ClientWidth  div 2,
  77.                              Form1.MChSpriteBgr1.ClientHeight div 2));
  78.   end;
  79.  
  80. procedure OnCollide(SprCollided: TMChSprite; AtTime: TDateTime);
  81.   begin
  82.   if SprCollided=Form1.MChSprite2 then
  83.     begin
  84.     if not CollideFlip then
  85.       begin
  86.       MessageBeep(MB_ICONASTERISK);
  87.       CollideFlip:=True;
  88.       end;
  89.     if Form1.MChSprite3.SprNextPos.x<Form1.MChSpriteBgr1.ClientWidth div 2 then
  90.       begin
  91.       if Form1.MChSprite3.SprIndex<Form1.MChSprite2.SprIndex then
  92.         Form1.MChSpriteBgr1.BgrSprIndexExchangeZ(Form1.MChSprite3.SprIndex,
  93.           Form1.MChSprite2.SprIndex);
  94.       end
  95.     else
  96.       begin
  97.       if Form1.MChSprite3.SprIndex>Form1.MChSprite2.SprIndex then
  98.         Form1.MChSpriteBgr1.BgrSprIndexExchangeZ(Form1.MChSprite3.SprIndex,
  99.           Form1.MChSprite2.SprIndex);
  100.       end;
  101.     end;
  102.   end;
  103.  
  104. procedure NoCollide(AtTime: TDateTime);
  105.   begin
  106.   if CollideFlip then
  107.     begin
  108.     MessageBeep(MB_OK);
  109.     end;
  110.   CollideFlip:=False;
  111.   end;
  112.  
  113. end.
  114.